<template>
  <div class="user-num" v-if="pageflag">

      <!-- <div>
        <img src="../../assets/img/dp/icon09.png" alt="">
      </div> -->
      <div class="num-box">
         <AnimatedNumber :value="count" :round="1" :format="formatToPrice" /> <span class="unit">组</span>
      </div>

  </div>
  <Reacquire v-else @onclick="getData" style="line-height: 200px">
    重新获取
  </Reacquire>
</template>

<script>
import * as API from "@/api";
import AnimatedNumber from "animated-number-vue";
let style = {
  fontSize: 22
}
export default {
  components: {
    AnimatedNumber
  },
  data() {
    return {
      pageflag: true,
      timer: null,
      count: 0
    };
  },
  created() {

  },

  mounted() {
     this.getData();
     this.switper();
  },
  beforeDestroy() {
    this.clearData();
  },
  methods: {
    clearData() {
      if (this.timer) {
        clearInterval(this.timer);
        this.timer = null;
      }
    },
    getData() {
      this.pageflag = true;
      const URL = '/super/screen/battery_stat';
      // const URL = '/admin/screen/order_stat';
      API.GET(URL).then(res => {
        if(res.code === 1){
          console.log(res)
          const { risk, stock, store, use } =  res.data
          this.count = risk+ stock+ store+ use
        } else {
          this.pageflag = false;

        }
      })
    },
    //轮询
    switper() {
      if (this.timer) {
        return;
      }
      let looper = (a) => {
        this.getData();
      };
      this.timer = setInterval(
        looper,
        1 * 60 * 1000
      );
    },
    formatToPrice(value) {
      return `${value.toFixed(2)}`;
    }
  },
};
</script>
<style lang='scss' scoped>
.right_top_inner {
  margin-top: -8px;
}
.user-num {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  height: 97%;
  background-image: url('../../assets/img/dp/bg01.png');
  background-size: 100% 100%;
  background-repeat: no-repeat;
  position: relative;
  .num-box {
    width: 100%;
    font-size: 100px;
    text-align: center;
    font-family: "DS-Digital";
     color: #fff;
    .unit {
      font-size: 20px;
    }
  }
}
</style>
